<!-- 购物车组件 -->
<template>
    <div>
      <h2>购物车</h2>
      <ul>
        <li v-for="(item, index) in items" :key="item.id">
          {{ item.name }} - ￥{{ item.price }}
          <button @click="removeFromCart(index)">移除</button>
        </li>
      </ul>
      <p>总价：￥{{ totalPrice }}</p>
    </div>
  </template>
  
  <script>
  export default {
    computed: {
      items() {
        return this.$store.state.cart
      },
      totalPrice() {
        return this.$store.getters.totalPrice
      }
    },
    methods: {
      removeFromCart(index) {
        this.$store.commit('removeFromCart', index)
      }
    }
  }
  </script>